package com.web.dao;

import com.web.entity.Message;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class MessageSqlProvider {


    public String insertSelective(Message record) {
        BEGIN();
        INSERT_INTO("t_message");

        if (record.getTarget() != null) {
            VALUES("target", "#{target,jdbcType=BIGINT}");
        }

        if (record.getTargetName() != null) {
            VALUES("target_name", "#{targetName,jdbcType=VARCHAR}");
        }

        if (record.getTitle() != null) {
            VALUES("title", "#{title,jdbcType=VARCHAR}");
        }

        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }

        if (record.getFrom() != null) {
            VALUES("`from`", "#{from,jdbcType=BIGINT}");
        }

        if (record.getFromName() != null) {
            VALUES("from_name", "#{fromName,jdbcType=VARCHAR}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(Message record) {
        BEGIN();
        UPDATE("t_message");

        if (record.getTarget() != null) {
            SET("target = #{target,jdbcType=BIGINT}");
        }

        if (record.getTargetName() != null) {
            SET("target_name = #{targetName,jdbcType=VARCHAR}");
        }

        if (record.getTitle() != null) {
            SET("title = #{title,jdbcType=VARCHAR}");
        }

        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }

        if (record.getFrom() != null) {
            SET("`from` = #{from,jdbcType=BIGINT}");
        }

        if (record.getFromName() != null) {
            SET("from_name = #{fromName,jdbcType=VARCHAR}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }


}